package com.rockcent.mall.lib.helper;

import com.rockcent.common.common.BusinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by oyhk on 16/7/18.
 * Update by zhangjh on 17/5/9.
 * 短信网关解耦
 */
public class BaseSMSHelper {
    private static Logger logger = LoggerFactory.getLogger(BaseSMSHelper.class);

    @Autowired
    private SMSStrategy smsStrategy;


    public boolean send(String mobile, String code) {
        String response = null;
        try {
            response = smsStrategy.send(mobile, code);
        } catch (BusinessException e) {
            logger.error(e.getMessage(), e);
        }
        return smsStrategy.handleResponse(response);
    }

    public boolean send(String mobile, String code, String name) {
        String response = null;
        try {
            response = smsStrategy.send(mobile, code, name);
        } catch (BusinessException e) {
            logger.error(e.getMessage(), e);
        }
        return smsStrategy.handleResponse(response);
    }


}
